package com.atchangsha.system.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.atchangsha.system.constant.OrderConstants;
import com.atchangsha.system.dto.OrderDTO;
import com.atchangsha.system.dto.PlaceAnOrderDTO;
import com.atchangsha.system.dto.WorkerDTO;
import com.atchangsha.system.entity.OrderEntity;
import com.atchangsha.system.vo.ResultVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import com.atchangsha.system.service.OrderService;
import com.atchangsha.system.common.utils.PageUtils;
import com.atchangsha.system.common.utils.Result;

import javax.annotation.Resource;


/**
 * 订单表
 *
 * @author 卓越班项目第二组
 * @date 2022-04-22 00:49:59
 */
@RestController
@RequestMapping("system/order")
@CrossOrigin
public class OrderController {
    @Resource
    private OrderService orderService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public Result list(@RequestParam Map<String, Object> params) {
        PageUtils page = orderService.queryPage(params);
        return Result.ok().setResult(page);
    }

    /**
     * 查询所有订单
     *
     * @return
     */
    @GetMapping("/listAll")
    public Result listAll() {
        return orderService.listAll();
    }

    /**
     * 下单
     */
    @PostMapping("/placeAnOrder")
    public Result placeAnOrder(@RequestBody PlaceAnOrderDTO placeAnOrderDTO) {
        return orderService.placeAnOrder(placeAnOrderDTO);
    }

    /**
     * 修改订单信息
     */
    @PutMapping("/update")
    public Result update(@RequestBody OrderDTO orderDTO) {
        return orderService.updateOrder(orderDTO.toEntity());
    }

    @GetMapping("/sum")
    public Result sum() {
        ResultVO resultVO = orderService.sum();
        return Result.ok().setResult(resultVO);
    }

    @GetMapping("/sumListAll")
    public Result sumListAll() {
        ResultVO resultVO = orderService.sumListAll();
        return Result.ok().setResult(resultVO);
    }

}
